<?php
namespace Admin\Controller;
use Think\Controller;
//后台登陆
class PublicController extends Controller {
	//验证码
	public function yanzma(){
		
		$Verify =     new \Think\Verify();
		// 验证码字体大小
		$Verify->fontSize = 50;
		// 验证码位数
		$Verify->length   = 3;
		// 关闭验证码杂点
		$Verify->useNoise = false;
		$Verify->entry();

	}
	
	 public function login(){

		$this->display();

	}
	// 检测输入的验证码是否正确，$code为用户输入的验证码字符串
	public function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}
	//判断登陆
	public function logincheck(){
		$code = $_POST["code"];
		$name = $_POST["name"];
		$pass = $_POST["password"];
		$result =M('user')->where("name = '$name' and password = '$pass'")->select();
		if(!empty($result)&&$this->check_verify($code)){
			session('name',$name);		//设置session
			
			$this->redirect("index/index");
		}else{
			$this->redirect("Public/login");
			
		}
		
	}
	//退出
	public function loginout(){
		
		//清空session
		session('name',null); // 删除name
		
		//进入登录界面
		//$this->login();
		$this->redirect("Public/login");
	}
	
}